//
//  LDJ_PhotoViewController.m
//  Pianke
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "LDJ_PhotoViewController.h"

@interface LDJ_PhotoViewController ()

@end

@implementation LDJ_PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.bigScrollView = [[UIScrollView alloc]init];
    self.bigScrollView.backgroundColor = [UIColor blackColor];
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.bounces = NO;
    [self.view addSubview:self.bigScrollView];
    //签协议
    self.bigScrollView.delegate = self;
    self.bigScrollView.contentOffset = CGPointMake(SCREEN_WIDTH * (self.photoNumber - 1), SCREEN_HEIGHT);
    [self.bigScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT));
        
    }];
    
    
    
    
    self.bigScrollView.contentSize = CGSizeMake(SCREEN_WIDTH * self.photoArray.count, SCREEN_HEIGHT);
    
    for (int i = 0; i < self.photoArray.count; i++) {
        
        //创建小View
        UIScrollView *sonView = [[UIScrollView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/20 + SCREEN_WIDTH * i, 0, SCREEN_WIDTH - SCREEN_WIDTH/10, SCREEN_HEIGHT)];
        sonView.backgroundColor = [UIColor blackColor];
        [self.bigScrollView addSubview:sonView];
        
        
        UIImageView *photoImgView = [[UIImageView alloc]initWithFrame:sonView.bounds];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self.photoArray[i]]];
        [photoImgView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
        [sonView addSubview:photoImgView];
        //图片适应原图大小
        photoImgView.contentMode = UIViewContentModeScaleAspectFit;
        
        //设置代理
        sonView.delegate = self;
        
//        [sonView mas_makeConstraints:^(MASConstraintMaker *make) {
//            
//            make.left.mas_equalTo(SCREEN_WIDTH/20 + SCREEN_WIDTH * i);
//            make.top.mas_equalTo(0);
//            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - SCREEN_WIDTH/10, SCREEN_HEIGHT));
//        }];
//        [photoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//            
//            make.left.mas_equalTo(SCREEN_WIDTH/20 + SCREEN_WIDTH * i);
//            make.top.mas_equalTo(0);
//            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - SCREEN_WIDTH/10, SCREEN_HEIGHT));
//            
//        }];
        
    }
    
    
    
    //页数
    self.imgNumber = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/10, SCREEN_HEIGHT - SCREEN_WIDTH/8, SCREEN_WIDTH/6, SCREEN_WIDTH/20)];
    self.imgNumber.font = [UIFont systemFontOfSize:EACH_HEIGHT * 15];
    self.imgNumber.textColor = [UIColor whiteColor];
    [self.view addSubview:self.imgNumber];
    self.imgNumber.text = [NSString stringWithFormat:@"%ld / %ld", self.photoNumber, self.photoArray.count];
    
    
    //轻拍
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.bigScrollView addGestureRecognizer:tap];
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    self.photoNumber = self.bigScrollView.contentOffset.x/SCREEN_WIDTH + 1;
    
    self.imgNumber.text = [NSString stringWithFormat:@"%ld / %ld", self.photoNumber, self.photoArray.count];
    
}



-(void)tapAction:(UITapGestureRecognizer *)tap{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
